//
//  BluSearchVController.m
//  DoorBell
//
//  Created by eques on 2023/9/13.
//  Copyright © 2023 eques. All rights reserved.
//

#import "BluSearchVController.h"

@interface BluSearchVController ()
@property(nonatomic,strong)UIView *contrainView;
@property(nonatomic,strong)UIButton *addButton;
@property(nonatomic,strong)UIButton *dismissButton;
@end

@implementation BluSearchVController

- (void)viewDidLoad {
    [super viewDidLoad];
    
     self.view.backgroundColor = [UIColor whiteColor];
     self.contrainView.backgroundColor = [UIColor whiteColor];
    [self.dismissButton setImage:[UIImage imageNamed:@"3.0_close_popup"] forState:UIControlStateNormal];
    [self.addButton setTitle:NSLocalizedString(@"add", nil) forState:UIControlStateNormal];
    NSLog(@"[UIScreen mainScreen].bounds.size.height=== %f",[UIScreen mainScreen].bounds.size.width);
}



- (UIView*)contrainView
{
    if (!_contrainView) {
         _contrainView = [[UIView alloc]init];
         _contrainView.layer.cornerRadius = 15;
         _contrainView.layer.masksToBounds = YES;
        [self.view addSubview:_contrainView];
        [_contrainView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.view.mas_left);
            make.right.equalTo(self.view.mas_right);
            make.bottom.equalTo(self.view.mas_bottom).offset(15);
            if(kScreenHeight > 667){
                make.height.mas_equalTo(kScreenHeight*0.45);
            }else{
                make.height.mas_equalTo(kScreenHeight*0.5);
            }
        }];
        
        UILabel *_titleLabel = [[UILabel alloc]init];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.textColor = [UIColor blackColor];
        _titleLabel.font = [UIFont fontWithName:@"PingFangSC-Medium" size:20.0];
        _titleLabel.text = NSLocalizedString(@"发现设备", nil);
       [_contrainView addSubview:_titleLabel];
       [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
           make.centerX.equalTo(_contrainView.mas_centerX);
           make.top.equalTo(_contrainView.mas_top).offset(20);
       }];
        
        UIImageView *lockimage = [[UIImageView alloc]init];
        
        if(self.is_cat){
            lockimage.image = [UIImage imageNamed:@"add_pet_feeder"];
        }else{
            lockimage.image = [UIImage imageNamed:@"vl0_add_smart_lock"];
        }
       [_contrainView addSubview:lockimage];
       [lockimage mas_makeConstraints:^(MASConstraintMaker *make) {
           make.top.equalTo(_titleLabel.mas_bottom).offset(20);
           make.centerX.equalTo(_contrainView.mas_centerX);
         
           if(self.is_cat){
               make.width.mas_equalTo(40);
               make.height.mas_equalTo(60);
           }else{
               make.width.mas_equalTo(60);
               make.height.mas_equalTo(120);
           }
       }];
       
        UILabel *_result_label = [[UILabel alloc]init];
       [_contrainView addSubview:_result_label];
        if(self.is_cat){
            _result_label.text = NSLocalizedString(@"宠物设备", nil);
        }else{
            _result_label.text = NSLocalizedString(@"智能锁", nil);
        }
       [_result_label sizeToFit];
        _result_label.textColor = [UIColor blackColor];
        _result_label.font = [UIFont fontWithName:@"PingFang-SC-Medium" size:16.0];
       [_contrainView addSubview:_result_label];
       [_result_label mas_remakeConstraints:^(MASConstraintMaker *make) {
          
           if(self.is_cat){
               make.centerX.equalTo(lockimage.mas_centerX);
           }else{
               make.centerX.equalTo(lockimage.mas_centerX).offset(-9);
           }
           make.top.equalTo(lockimage.mas_bottom).offset(10);
       }];
        
    }
    return _contrainView;
}


- (UIButton*)dismissButton
{
    if (!_dismissButton) {
         _dismissButton = [[UIButton alloc]init];
        [_dismissButton addTarget:self action:@selector(dismissClick:) forControlEvents:UIControlEventTouchUpInside];
       [self.contrainView addSubview:_dismissButton];
       [_dismissButton mas_makeConstraints:^(MASConstraintMaker *make) {
           make.right.equalTo(self.contrainView.mas_right).offset(-4);
           make.top.equalTo(self.contrainView.mas_top);
           make.width.height.mas_equalTo(40);
       }];
    }
    return _dismissButton;
}

- (void)dismissClick:(UIButton*)sender
{
    [self dismissViewControllerAnimated:YES completion:^{
    }];
    if (self.dismissClickBlock) {
        self.dismissClickBlock(sender);
    }
}



- (UIButton*)addButton
{
    if (!_addButton) {
        _addButton = [[UIButton alloc]init];
        _addButton.titleLabel.font = [UIFont fontWithName:@"PingFangSC-Medium" size:20.0];
       [_addButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _addButton.layer.cornerRadius = 12;
        _addButton.layer.masksToBounds = YES;
        _addButton.backgroundColor = [UIColor orangeColor];
       [_addButton addTarget:self action:@selector(addButtonClick:) forControlEvents:UIControlEventTouchUpInside];
       [self.view addSubview:_addButton];
       [_addButton mas_makeConstraints:^(MASConstraintMaker *make) {
           make.left.equalTo(self.view.mas_left).offset(14);
           make.right.equalTo(self.view.mas_right).offset(-14);
           make.width.height.mas_equalTo(45);
           if(kScreenHeight >= 667){
               make.bottom.equalTo(self.view.mas_bottom).offset(-25);
           }else{
               make.bottom.equalTo(self.view.mas_bottom).offset(-10);
           }
           
       }];
        [_addButton setTitle:NSLocalizedString(@"添加", nil) forState:UIControlStateNormal];
    }
    return _addButton;
}

- (void)addButtonClick:(UIButton*)sender
{
    [self dismissViewControllerAnimated:YES completion:^{
    }];
    if (self.addClickBlock) {
        self.addClickBlock(sender);
    }
    
}



@end
